package main

import (
	"fmt"
	"sync"
)

var lock sync.Mutex
var wg sync.WaitGroup
var x = 0

func add(){
	defer wg.Done()
	lock.Lock() //加锁
	x++
	lock.Unlock() //释放锁
}

func main()  {
	for i := 0; i < 100; i++ {
		wg.Add(1)
		go add() //开起并发
	}
	wg.Wait()

	fmt.Println(x)
}